package com.readfeed.app.dialogs;

import com.readfeed.app.R;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.app.DialogFragment;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;

public class AddChannelDialogFragment extends DialogFragment {
	private DialogEventsListener mListener;
    
	public static AddChannelDialogFragment newInstance(){
		AddChannelDialogFragment dialogFragment = new AddChannelDialogFragment();
		return dialogFragment;
	}
	
	@Override
	public void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		this.setCancelable(false);
		this.setRetainInstance(false);
	}
	
    @Override
    public void onAttach(Activity activity) {
        super.onAttach(activity); 
        try { 
            mListener = (DialogEventsListener) activity;
        } catch (ClassCastException e) {            
            throw new ClassCastException(activity.toString()
                    + " must implement NoticeDialogListener");
        }
    }
    
    @Override
	public Dialog onCreateDialog(Bundle savedInstanceState) {
    	Activity activity = getActivity();
		AlertDialog.Builder builder = new AlertDialog.Builder(activity);
		LayoutInflater inflater = activity.getLayoutInflater();
		
		View dialogView = inflater.inflate(R.layout.add_channel_dialog, null);		
		builder.setView(dialogView)
			.setTitle(R.string.add_channel_dialog_title)
	       	.setPositiveButton(R.string.submit_button, new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					mListener.onDialogPositiveClick(AddChannelDialogFragment.this);					
				}
			})
			.setNegativeButton(R.string.cancel_button, new DialogInterface.OnClickListener() {
				
				@Override
				public void onClick(DialogInterface dialog, int which) {
					mListener.onDialogNegativeClick(AddChannelDialogFragment.this);					
				}
			});
		
		Dialog dialog = builder.create();
		dialog.setCancelable(false);
		return dialog;
	}
}
